//
//  CZPingLunCell.swift
//  GZWeibo666
//
//  Created by mac－gt on 15/12/1.
//  Copyright © 2015年 itcast. All rights reserved.
//

import UIKit

class CZPingLunCell: UITableViewCell {
    var comment: CZCommentStatus?{
        didSet{
            if let imagUrl=comment?.user?.profile_image_url{
           iconView.sd_setImageWithURL(NSURL(string: imagUrl))
        }
            nameLabel.text=comment?.user?.screen_name
            timeLabel.text=comment?.created_at
            verifiedImageView.image=comment?.user?.verifiedImage
            mbrankImageView.image=comment?.user?.mbrankImage
                contentLabel.text=comment?.text
        }
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setUp()
    }

    private func setUp() {

        contentView.addSubview(iconView)
        contentView.addSubview(nameLabel)
        contentView.addSubview(timeLabel)
        contentView.addSubview(contentLabel)
        contentView.addSubview(mbrankImageView)
        contentView.addSubview(verifiedImageView)
         
        iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size: CGSize(width: 35, height: 25), offset: CGPoint(x: 8, y: 8))
   
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        mbrankImageView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 8, y: 0))
      
        verifiedImageView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))
          contentLabel.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: timeLabel, size: nil, offset: CGPoint(x: 0, y: 8))
        contentView.addConstraint(NSLayoutConstraint(item: contentLabel, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: -8))

        contentView.addConstraint(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: contentLabel, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 8))

    }
    

    private lazy var iconView: UIImageView = UIImageView()
    private lazy var nameLabel: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    private lazy var timeLabel: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    private lazy var contentLabel: UILabel = {
      let lable = UILabel(color: UIColor.lightGrayColor(), fontSize: 14)
        lable.numberOfLines=0
        return lable
    }()
    private lazy var mbrankImageView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    private lazy var verifiedImageView:  UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))


}
